﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Yunwei.Common
{
    public class PathUtil
    {
        public static string PhysicPathToRelativePath(string appRootDir, string physicPath)
        {
            string url = physicPath.Replace(appRootDir, ""); //转换成相对路径
            url = url.Replace(@"\", @"/");
            return url;
        }

        public static string UrlToRelativePath(string url, string authority)
        {
            if (url.Contains("http://"))
            {
                url = url.Replace("http://" + authority, "");
            }
            else if (url.Contains("https://"))
            {
                url = url.Replace("https://" + authority, "");
            }
            else
            {
                url = url.Replace(authority, "");
            }

            url = url.Contains("?") ? url.Split('?')[0] : url;

            return url;
        }

        public static string GetThumbnailPath(string originPath)
        {
            string fileName = System.IO.Path.GetFileNameWithoutExtension(originPath);
            string pathRoot = System.IO.Path.GetDirectoryName(originPath);
            string thumbnailPath = pathRoot + "\\" + fileName + "_thumbnail" + System.IO.Path.GetExtension(originPath);

            return thumbnailPath;
        }

        public static string GetTempPath(string originPath)
        {
            string fileName = System.IO.Path.GetFileNameWithoutExtension(originPath);
            string pathRoot = System.IO.Path.GetDirectoryName(originPath);
            string tempPath = pathRoot + "\\" + Guid.NewGuid().ToString("N") + System.IO.Path.GetExtension(originPath);

            return tempPath;
        }
    }
}
